package com.shaobufan.museum.controllar;

import com.shaobufan.museum.common.BaseResponse;
import com.shaobufan.museum.common.ResultUtils;
import com.shaobufan.museum.pojo.vo.FileVO;
import com.shaobufan.museum.service.UploadService;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/*
图片OSS
 */
@RestController
@RequestMapping("/file")
public class FileController {

    @Resource
    private UploadService uploadService;

    @ApiOperation("上传图片")
    @PostMapping("/upload")
    public BaseResponse<FileVO> upload(@RequestPart("file") MultipartFile file) throws IOException {
        FileVO upload = uploadService.upload(file);
        return ResultUtils.success(upload, "上传成功");
    }
}